﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Data.Repositories;
using Sita.Entities;

namespace Sita.MainModule.Services
{
    public class UserService
    {
        UserRepository UserRepository;
        PermissionService PermissionsService;
        BusinessUnitService BusinessUnitService;

        public UserService()
        {
            UserRepository = new UserRepository();
        }

        public List<User> GetAllUsers()
        {
            return UserRepository.GetAll().ToList();
        }

        public User GetUserByUserName(string name)
        {
            return UserRepository.GetByUserName(name);
        }

        public bool ModifyUser(User user)
        {
            UserRepository.Modify(user);

            UserRepository.StoreContext.Commit();
            return true;
        }

        public IList<Permission> GetUserPermissions(int userID)
        {
            PermissionsService = new PermissionService();
            return PermissionsService.GetPermissionsByUserID(userID);
        }

        public BusinessUnit GetUserBusinessUnits(int userID)
        {
            BusinessUnitService = new BusinessUnitService();
            return BusinessUnitService.GetBusinessUnitsByUserID(userID);
        }
    }
}
